package c2.advanced.business.base;

import c2.advanced.business.AdvancedBody;
import c2.advanced.business.common.CommonModule;
import c2.advanced.share.PlayFacade;
import c2.advanced.share.TableFacade;
import cp.solution.rpc.template.RpcReceiverTemplate;
import cp.solution.rpc.template.RpcSenderTemplate;
import lombok.Setter;

public abstract class AdvancedSubModule<PARENT extends AdvancedModule, C extends AdvancedBody> {

    @Setter
    protected PARENT parent;

    protected C context;

    protected RpcSenderTemplate useRpcSend() {
        return context.rpc.send();
    }

    protected RpcReceiverTemplate useRpcRecv() {
        return context.rpc.recv();
    }

    protected TableFacade useTable() {
        return context.table;
    }

    protected PlayFacade usePlay() {
        return context.play;
    }

    protected CommonModule useCommon() {
        return context.common;
    }


    public void initIndependent(ModuleRequirements requirements, C context) throws Exception {
        this.context = context;
    }

    public void initDependent() throws Exception {
    }

    /** 受主模块节奏控制的间隔触发 */
    public void onInterval() throws Exception {
    }

    public void onShutdown() throws Exception {

    }
}
